package io.renren.modules.gasstation.gasstationenterprise.controller;

import io.renren.common.utils.R;
import io.renren.modules.gasstation.gasstationenterprise.entity.GasStationEnterpriseEntity;
import io.renren.modules.gasstation.gasstationenterprise.service.GasStationEnterpriseService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;
import java.util.List;
import java.util.Map;

/**
 * @Author：T-weiwei
 * @Description: 加油站企业接口层
 * @Email：tweiwei@aliyun.com
 * @CreateDate：2022-01-10-下午3:42
 * @CopyRight：http://www.huaxun.ink/
 * @Hint： This content is limited to the internal circulation of HuaXun Hi Tech Co., Ltd.,
 * and is forbidden to be leaked and used for other commercial purposes
 **/
@RestController
@RequestMapping("gasstation/gasstationenterprise")
public class GasStationEnterpriseController {

    /**
     * 加油站企业业务层
     */
    @Autowired
    private GasStationEnterpriseService gasStationEnterpriseService;

    /**
     * 分页查询列表
     * @param params
     * @return
     */
    @GetMapping("/list")
    public R list(@RequestParam Map<String, Object> params){
        // TODO 先用所有列表代替分页，后期有时间会补上
        List<GasStationEnterpriseEntity> list = this.gasStationEnterpriseService.list();
        return R.ok().put("page", list);
    }

    /**
     * 根据id获取加油站企业信息
     * @param id 主键id
     * @return 是否成功标识
     */
    @GetMapping("/info/{id}")
    public R info(@PathVariable("id") Long id){
        GasStationEnterpriseEntity entity = this.gasStationEnterpriseService.getById(id);
        return R.ok().put("gasStationEnterpriseEntity", entity);
    }

    /**
     * 保存加油站企业数据
     * @param enterpriseEntity 加油站企业实体类
     * @return 是否成功标识
     */
    @PostMapping("/save")
    public R save(@RequestBody GasStationEnterpriseEntity enterpriseEntity){
        this.gasStationEnterpriseService.save(enterpriseEntity);
        return R.ok();
    }

    /**
     * 修改加油站企业数据
     * @param enterpriseEntity 加油站企业实体类
     * @return 是否成功标识
     */
    @PostMapping("/update")
    public R update(@RequestBody GasStationEnterpriseEntity enterpriseEntity){
        this.gasStationEnterpriseService.update(enterpriseEntity);
        return R.ok();
    }

    /**
     * 根据主键id删除指定数据
     * @param id 主键id
     * @return 是否成功标识
     */
    @PostMapping("/delete/{id}")
    public R delete(@PathVariable Long id){
        this.gasStationEnterpriseService.removeById(id);
        return R.ok();
    }

}
